home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 50
/
Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso
/
Aminet
/
util
/
rexx
/
ParseRX.lha
/
ParseRX
next >
Wrap
Text File
|
2001-06-06
|
7KB
|
298 lines
/* ParseRX by Brucey (one stupidly simple ARexx Utility:) */
/* this whole program is based around this loop...
DO FOREVER
CALL WRITECH(STDOUT, '1B'X || '[33m'RC'' || '1B'X || '[31m:' || '1B'X || '[32m'address()'' || '1B'X || '[31m: ')
PRX_LN=READLN(STDIN)
INTERPRET PRX_LN
END
you would type the command "exit" to leave it
all the rest of this script is fancy functions
to aid in making/debugging arexx functions
*/
/*
commands so far are ...
Q,EXIT or <return>(twice) will Quit ParseRX
SHP = same as typing "say show('p')"
ADC = ADDRESS COMMAND
ADR portname = address portname (ADRQ for Requester)
ADV portname = address value portname (ADVQ for Requester)
ALIB / RLIB to Add Revove ARexx libraries
*/
OPTIONS RESULTS
PRX_LibPat = 'libs:#?rex#?'
/* intro message */
CALL WRITECH(STDOUT, '1B'X || '[32mParseRX... Type Q or exit to Quit, HELP for info' || '0A'X || '')
/* get an srgument for a port to open on , or it uses the port "COMMAND" */
INTERPRET 'ADDRESS' ARG(1)
/* this stuff handles errors that would normally exit an arexx script */
OPTIONS FAILAT 100
ERROR: IF (RC>0)&(RC~='RC') THEN DO; SAY 'ERROR 'RC':' ErrorText(RC) 'line: 'SIGL; RC= ; END
SYNTAX: IF (RC>0)&(RC~='RC') THEN DO; SAY SYNTAX RC':' ErrorText(RC) 'line: 'SIGL; ; END
HALT: IF (RC>0)&(RC~='RC') THEN DO; SAY 'HALT : Interrupt call! line: 'SIGL; END
FAILURE: IF (RC>0)&(RC~='RC') THEN DO; SAY 'FAILURE :' ErrorText(RC) 'line: 'SIGL; END
SIGNAL ON ERROR
SIGNAL ON HALT
SIGNAL ON FAILURE
SIGNAL ON SYNTAX
/* after typing some input the RETURN and RC vars are copied to
PRX_RESULT and PRX_RC and displayed at the console prompt,
so 1st we set them to display '-' */
PRX_RC='-'
PRX_RESULT='-'
/* Get a list of arexx libraries acc to PRX_LibPat (at top of file) */
ADDRESS COMMAND 'list 'PRX_LibPat' lformat "%n" to pipe:temp'
PRX_Libs=''
CALL OPEN('h','pipe:temp')
DO WHILE ~EOF('h')
PRX_String = READLN('h')
IF PRX_String~="" then PRX_Libs = PRX_Libs''prx_String' '
END
CALL CLOSE('h')
PRX_Libs=Strip(PRX_Libs)
call open('h','ENV:ClassAct/ClassAct')
PRX_ln=readln('h')
call close('h')
parse var prx_ln 'FALLBACKFONT "' PRX_fname'/'PRX_fsize '"' .
if PRX_fname=='' | PRX_fsize=='' then do
PRX_fname='Topaz.font'
PRX_fsize=8
end
/* THE MAIN LOOP */
DO FOREVER
/* write the prompt as RC|RESULT|ADDRESS: (plus some colour) */
CALL WRITECH(STDOUT, '1B'X || '[33m'PRX_RC'' || '1B'X || '[31m:' || '1B'X || '[32m'address()'' || '1B'X || '[31m: ')
/* Wait for user input from STDIN console */
PRX_LN=READLN(STDIN)
SELECT
/* if you only press return you are asked if you want to quit */
WHEN PRX_LN=="" THEN DO
CALL WRITECH(STDOUT,'I Am Going to Quit ? (<return> for OK):');
IF READLN(STDIN)=='' THEN CALL QIT()
END
WHEN UPPER(PRX_LN)=='Q' | UPPER(PRX_LN)=='QUIT' THEN CALL QIT()
/* print help */
WHEN UPPER(PRX_LN)=='HELP' THEN DO
SAY ''
SAY 'ParseRX Written by bsteers@ukonline.co.uk' || '0A'X || 'HELP for Commands.....'
SAY 'Q,EXIT or <return>(twice) will Quit ParseRX'
SAY 'SHP = say show(''p'')'
SAY 'ADC = ADDRESS COMMAND'
SAY 'ADR portname = address portname, ADRQ for Req'
SAY 'ADV portname = address value portname, ADVQ for Req'
SAY 'ALIB / RLIB to Add Revove ARexx libraries'
END
/* other functions */
WHEN UPPER(PRX_LN)=='ADC' THEN ADDRESS COMMAND
WHEN WORD(UPPER(PRX_LN),1)=='ADR' THEN ADDRESS(WORD(PRX_LN,2))
WHEN WORD(UPPER(PRX_LN),1)=='ADV' THEN ADDRESS VALUE WORD(PRX_LN,2)
WHEN UPPER(PRX_LN)=='ADRQ' THEN ADDRESS(ADRES('*'))
WHEN UPPER(PRX_LN)=='ADVQ' THEN ADDRESS VALUE ADRES('*')
WHEN UPPER(PRX_LN)=='ALIB' THEN CALL ARLIB('Adding')
WHEN UPPER(PRX_LN)=='RLIB' THEN CALL ARLIB('Removing')
WHEN UPPER(PRX_LN)=='SHP' THEN SAY SHOW('P')
OTHERWISE DO
/* if no commands are given just interpret the line */
INTERPRET PRX_LN
/* set RC/RESULT vars back to '-' if they are not any value */
IF RESULT=='RESULT' THEN PRX_RESULT='-'; ELSE; PRX_RESULT=RESULT
IF RC=='RC' THEN PRX_RC='-'; ELSE;PRX_RC=RC
END
END
END /* END of the MAIN LOOP */
QIT:
SAY 'GoodBye :)'
EXIT
/* add/remove arexx libraries */
ARLIB:
PRX_Mode = Arg(1)
PRX_Count = 1
PRX_Mark = 1
drop PRX_ALib.
PRX_ALibs = show('L')
drop PRX_List.
IF PRX_Mode == 'Adding' THEN DO
DO PRX_Count=1 to words(PRX_Libs)
if index( upper(PRX_ALibs) , upper( word(PRX_Libs,PRX_Count)) )==0 then do
PRX_List.PRX_Mark = word(PRX_Libs,PRX_Count)
PRX_List.0 = PRX_Mark
PRX_Mark = PRX_Mark + 1
end
end
END
ELSE DO /* So Removing */
PRX_List.0 = words(PRX_ALibs)
IF PRX_List.0 ==0 then do
say 'no libraried added'
return
end
DO PRX_Count = 1 TO words( PRX_ALibs )
PRX_List.PRX_Count = word( PRX_Alibs, PRX_Count )
END
END
LIB_LIST = list('L','Libs for 'PRX_Mode)
IF LIB_LIST=='' | LIB_LIST=='LIB_LIST' then return
SAY PRX_Mode' libraries 'LIB_LIST
DO PRX_COUNT=1 TO WORDS(LIB_LIST)
IF PRX_Mode == 'Adding' THEN
CALL ADDLIB(WORD(LIB_LIST,PRX_COUNT),0,-30,0)
ELSE
CALL REMLIB(WORD(LIB_LIST,PRX_COUNT))
END
RETURN
ADRES:
IF ARG(1)=='*' THEN DO
drop PRX_List.
PRX_Count = 1
PRX_string = show('p',,'¿')
do while PRX_Count > 0
PRX_Mark = index(PRX_string,'¿')
if PRX_Mark == 0 then PRX_Count = -2
else do
PRX_List.PRX_Count = substr(PRX_String,1, PRX_Mark - 1)
PRX_String = substr(PRX_String, PRX_Mark + 1)
PRX_List.0 = PRX_Count
PRX_Count = PRX_Count + 1
end
end
NEW_PORT = list('P','Select a Port')
END
ELSE; NEW_PORT=ARG(1)
RETURN NEW_PORT
list:
call close(pipe)
if ~open(pipe,'awnpipe:new/xc') then exit(205)
call topipe('"'Arg(2)'" defg v a m')
if arg(1)=='P' THEN; PRX_LB = topipe('listbrowser lbl ""')
ELSE; PRX_LB = topipe('listbrowser m lbl ""')
PRX_MaxStr=0
PRX_Seld=''
do PRX_count=1 TO PRX_List.0
PRX_MaxStr = max(PRX_MaxStr,Length(PRX_List.PRX_Count))
call topipe('browsernode gt "'PRX_List.PRX_Count'"')
END
call topipe('layout b 0 si so weih 0')
PRX_OK = topipe('button gt "_OK" c')
PRX_Can = topipe('button gt "_Cancel" c')
call topipe('le')
prx_w = (PRX_MaxStr*PRX_fsize)+30
prx_h = ( PRX_List.0 * PRX_fsize)+30
call topipe('open')
call topipe('id 'PRX_LB' SORT=0')
call topipe('id 0 wide 'PRX_W' high 'PRX_H)
do while ~eof(pipe)
call topipe('con')
in=readln(pipe)
parse var in in1 in2 in3 in4 in5
if in1=='gadget' | in1=='close' then do
select
when in2==PRX_LB then PRX_Seld=strip(in5)
when in2==PRX_OK then do
if prx_seld=='' then do
say 'Nothing Selected'
call close(pipe)
if arg(1)=='P' then return address();else; return ''
end
end
otherwise do
call close(pipe)
say 'Aborted'
if arg(1)=='P' then return address();else; return ''
end
end
end
end
call close(pipe)
PRX_R=''
do PRX_Count=1 TO words(PRX_Seld)
PRX_Val = word(PRX_Seld,PRX_Count)-1
PRX_R=PRX_R''PRX_List.PRX_Val' '
END
PRX_R = strip(PRX_R)
return PRX_R
topipe:
parse arg out
call writeln(pipe,out); res=readln(pipe)
parse var res res1 res2 .
if res1='ok' then return(res2)
say 'error from: 'out; say ' responce: ' res; exit